//
//  UserCenterViewController.m
//  PictureSelector
//
//  Created by Lyy on 15/8/26.
//  Copyright (c) 2015年 Lyy. All rights reserved.
//

#import "UserCenterViewController.h"
#import "EMUploadProfile.h"

@interface UserCenterViewController ()


@property (weak, nonatomic) IBOutlet UIButton *userLogoButton;

@property (nonatomic ,strong)EMUploadProfile *profile;

@end

@implementation UserCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    [self.userLogoButton setImage:[UIImage imageNamed:@"userIcon.jpg"] forState:UIControlStateNormal];
    self.userLogoButton.layer.cornerRadius = CGRectGetHeight(self.userLogoButton.frame)/2.0;
    self.userLogoButton.layer.masksToBounds = YES;
    
    //阴影图层
    CALayer *layerShadow=[[CALayer alloc]init];
    layerShadow.bounds=self.userLogoButton.bounds;
    layerShadow.position= self.userLogoButton.center;
    layerShadow.cornerRadius=self.userLogoButton.layer.cornerRadius;
    layerShadow.shadowColor=[UIColor whiteColor].CGColor;
    layerShadow.shadowOffset=CGSizeMake(2, 1);
    layerShadow.shadowOpacity=1;
    layerShadow.borderColor=[UIColor whiteColor].CGColor;
    layerShadow.borderWidth=1;
    [self.view.layer addSublayer:layerShadow];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // 此处判断原因是：处理循环应用问题
    // 因为当前viewController 和 _profile 互相强引用对方，
    // 如果不把_profile 置为nil，都将释放不掉
    if (!self.presentedViewController) {
        // 需要把_profile 置为nil，否则会出现循环引用问题
        _profile = nil;
    }
}

- (IBAction)openPhone:(id)sender {
    
//    更换头像
    if (!_profile) {
        _profile = [[EMUploadProfile alloc] init];
    }
    [_profile uploadProfile:EMUploadProfileLoginWeibo profileUrl:@"http://tp1.sinaimg.cn/1404376560/50/0/1" rootViewController:self uploadComplete:^(UIImage *userProfileImage) {
        [_userLogoButton setImage:userProfileImage forState:UIControlStateNormal];
        [_userLogoButton setImage:userProfileImage forState:UIControlStateHighlighted];
    }];
}

- (void)dealloc {
    NSLog(@"------UserCenterViewController------");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
